package com.cheung.leetcode.greedy;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.greedy
 * @Author :  cheungming
 * @CreateTime : 2024-05-30 10:30:49
 * @Description : 分发饼干
 * @Version : 1.0
 */
public class Code455Test {

    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int j = 0;
        for (int k : s) {
            if (j < g.length && k >= g[j]) {
                j++;
            }
        }
        return j;
    }

    @Test
    public void test1() {
        int[] g = {1, 2, 3};
        int[] s = {1, 1};

        assert findContentChildren(g, s) == 1;
    }

    @Test
    public void test2() {
        int[] g = {1, 2};
        int[] s = {1, 2, 3};
        assert findContentChildren(g, s) == 2;
    }
}
